<!--
auth: 徐剑锋
-->
<html>
<head>
    <link rel="stylesheet" href="<?php echo IMG_PATH ?>admin/common.css?<?php echo STATIC_VER ?>">
    <link rel="stylesheet" href="<?php echo IMG_PATH ?>admin/bootstrap.min.css">
    <script>SITE_PATH='<?php echo SITE_PATH ?>';</script>
    <title>监控订单 - 千纸鹤管理平台</title>
    <style>
        table{background:#F0F8FF;}
        th{font-size: 18px;text-align: center;background:#FFEC8B;}
        td{font-size: 16px;text-align: center;}
        td,th{border:1px solid #a2a2a2;}
        tr:nth-of-type(odd){background:#FFFFE0;border:1px solid #a2a2a2;}
    </style>
</head>
<body>

<?php
echo $header;
date_default_timezone_set('PRC');
?>

<div id="body" style="min-width:100%;min-height:100%;overflow-y:hidden;">
    <div style="font-size:18px;margin:5px 0;">当前位置：设置＞＞权限 </div>

</div>
<?php if(isset($errors) || (isset($_GET['err']) && $errors=$_GET['err'])){ ?>
    <div class="alert alert-error"style="width:40%;padding: 15px 0;  text-align: center; color: red;background: pink;margin-left: 29%;margin-bottom: 10px;">
        <?php echo $errors;?>
    </div>
<?php }?>

<div style="width:100%;min-height:100%;overflow-y:hidden;background:#f1f4f6">
    <table width="96%" border="0" cellpadding="0" cellspacing="0" style="margin:0 auto;">
        <thead>
        <th>权限名称</th><th>工作人员</th><th>修改时间</th><th>操作</th>
        </thead>
        <tbody id="listTBody">

        <?php
        if(isset($jauth) && count($jauth)) {
            foreach($jauth as $data) { ?>
                <tr>
                    <td class="comment"><?php echo $data['comment'] ?></td>
                    <td style="width:60%;padding:3px 10px;word-break: normal;"><?php
                            $arr = explode(',',$data['ads_ids']);
                            $str ='';
                            foreach($arr as $v) {
                                $str .= ' , '.$j[$v];

                            }
                            echo trim($str,' , ');
                        ?>
                    </td>
                    <td style="max-width:167px;"><?php echo date('Y-m-d H:i:s', $data['time_add']) ?></td>
                    <td style="padding:5px;">
                        <button class ='btn btn-info toEdit'wids="<?php echo $data['worker_ids'];?>"aid="<?php echo $data['id'];?>">编辑</button>
                    </td>
                </tr>
            <?php }
        }else { ?>
            <tr>
                <td colspan="6" style="height:40px;">查无数据</td>
            </tr>

            <?php
        }
        ?>
        </tbody>
    </table>
</div>
<div style="width:100%;height:45px;">&nbsp;</div>
<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">

    <div class="modal-dialog">
        <form class="form-horizontal col-xs-10"id="form1"style="width:160%;left: -24.5%;">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">X</span></button>
                    <h4 class="modal-title" id="myModalLabel"></h4>
                </div>

                <div class="modal-body"style="min-height:160px;overflow:hidden;">

                    <div class="form-group">
                        <label for="inputName"class="col-sm-1 control-label"style="width:100px;font-size:16px;font-weight:normal;margin-right:0px;padding-right: 0px;">权限名称：</label>
                        <div class="col-sm-7"style="margin-left:0px;font-size:18px;">
                            <input type="text"class="form-control"id="inputAname"style="font-size:18px;border:0px;"readonly/>
                            <input type="hidden"id="inputAid"name="inputAid"/>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="inputName"class="col-sm-1 control-label"style="font-size:16px;font-weight:normal;margin-right:0px;padding-right: 0px;width:100px;">用户：</label>
                        <div class="col-sm-9"style="margin-left:14px;border:1px solid gray;border-radius:10px;padding:10px;width:82%;" id="workerList">

                        </div>
                    </div>

                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                    <button type="submit" class="btn btn-primary">保存</button>
                </div>

            </div></form>
    </div>

</div>

<script src="http://static.caocaod.com/libs/jquery/jquery-2.2.3.min.js"></script>
<script src="<?php echo IMG_PATH ?>admin/common.js?<?php echo STATIC_VER ?>"></script>
<script src="<?php echo IMG_PATH ?>admin/bootstrap.min.js"></script>

<script>
    var allwork = JSON.parse('<?php echo json_encode($jworker);?>');

    $('.toEdit').click(function() {
        $('#myModal #myModalLabel').html('编辑权限');
        $('#myModal #inputAname').val($(this).parents('tr').find('.comment').html());
        $('#myModal #inputAid').val($(this).attr('aid'));

        var wids = $(this).attr('wids').split(',');

        var str = '';
        for(var i in allwork) {
            str += '<div style="padding:1px 3px;;float:left;font-size:16px;font-weight: normal;min-width:123px;"><input type="checkbox" name="chk[]"value="'+i+'"id="w_'+i+'"'+(wids.indexOf(i)>-1?'checked':'')+'/><label for="w_'+i+'"style="font-weight: normal;">'+allwork[i]+'</label></div>';
        }

        $('#myModal #workerList').html(str);

        $('#myModal').modal('show');
    });

    $('#form1').submit(function() {

        $.ajax({
            type:'post',
            dataType:'json',
            data:$('#form1').serialize(),
            url:SITE_PATH+'admin/auths/updateAuth',
            success:function(msg) {
                $('#myModal').modal('hide');
                if(msg['result']==1) {
                    alert('编辑成功');
                    window.location.reload();
                }else {
                    alert('编辑失败，'+msg['msg']);
                    if(msg['result']==-1)
                        window.location.reload();
                }
            },
            error:function(msg) {
                $('#myModal').modal('hide');
                alert('_编辑失败，请稍侯再试');
            }
        })

        return false;
    });
</script>
</body>
</html>